//
//  RHDataMonitor233VC.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/8/27.
//

#import "RHDataMonitor233VC.h"
#import "RHDeviceItemDataCell.h"
#import "RHDeviceChartDataCell.h"
#import "RHDeviceTotalDataCell.h"
#import "RHFirmwareListVC.h"
#import "RHDeviceDataModel.h"
#import "RHDeviceModel.h"
#import "DevChartModel.h"
#import "DevChartTypeModel.h"
#import "DeviceChartFieldModel.h"
#import "DevChartParamsModel.h"
#import "ChoiceEndpointVC.h"
#import "RHWindowTipManage.h"
#import "DevParamsAlertController.h"
#import "WSDatePickerView.h"
#import "RHInvChartHeaderView.h"
#import "DeviceFullChartController.h"
#import "RHEndPointTypeModel.h"
#import "RHEndPointModel.h"
#import "RHTopoModel.h"
#import "RHDeviceDataSectionView.h"
#import "RHFieldsDataVC.h"
#import "RHInverterModel.h"
#import "SYChartTool.h"
#import "RHInverterStatisticsCell2.h"
#import "RHInverterStatisticsCell3.h"
#import "RHInverterParamterCell.h"
#import "KWTParaItemCell.h"
#import "KWTParaMeterCell.h"
#import "RHBatteryClusterChartCell.h"

#import "RHInvParamSelectView.h"
#import "RHInvParamModel.h"
#import "RHInvDoubleChartCell.h"
#import "RHParaSingleCell.h"
#import "RHOtherFieldsDataVC.h"
#import "RHDevPackModel.h"
#import "RHCellRealDataModel.h"
#import "RHBatteryClusterFullChartVC.h"
#import "RHDeviceBatteryVC.h"
#import "RHNavTitleView.h"

@interface RHDataMonitor233VC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) UITableView *tableView;

@property (nonatomic ,strong) RHInvChartHeaderView *headerView;

@property (nonatomic ,assign) __block NSInteger modelType;

//曲线参数,通过端点类型创建
@property (nonatomic ,strong) DevChartParamsModel *chartParamsModel;

@property (nonatomic ,strong) ChoiceEndpointVC *choiceEndpointVC;

//当前选中的子端点
@property(nonatomic,strong)RHEndPointModel *curEndPointModel;

//各型号的当前版本
@property(nonatomic,copy)NSString *curTypeVersion;
//数据源
@property (nonatomic ,strong) NSArray *dataArray;
//后台所有数据点,包括曲线  当前端点类型的
@property (nonatomic ,strong) NSArray *allFieldData;
//emu数据点  逆变器的电池信息参数要用到
@property (nonatomic ,strong) NSArray *emuFieldData;
//pcs数据点  233 Master参数信息要用到
@property (nonatomic ,strong) NSArray *pcsFieldData;
//meter数据点   233 EMU参数信息要用到
@property (nonatomic ,strong) NSArray *meterFieldData;
//master数据点  233 EMU运行数据要用到
@property (nonatomic ,strong) NSArray *masterFieldData;
//液冷数据点  233 EMU参数信息要用到
@property (nonatomic ,strong) NSArray *lcuFieldData;
//除湿机数据点  233 EMU参数信息要用到
@property (nonatomic ,strong) NSArray *dehumFieldData;
//单位数量
@property (nonatomic ,assign) NSInteger unitCount;
//曲线参数选择
@property (nonatomic ,strong) RHInvParamSelectView *paraSelectView;
//233k  master下电压电压和温度数据
@property (nonatomic ,strong) NSArray *cellDataArray;

//233k Master参数信息中有部分是PCS的参数
@property (nonatomic ,strong) RHEndPointModel *pcsEndpointModel;
//233k EMU参数信息中有部分是 电表 和 master, lcu dehum 的参数
@property (nonatomic ,strong) RHEndPointModel *meterEndpointModel;
@property (nonatomic ,strong) RHEndPointModel *masterEndpointModel;
@property (nonatomic ,strong) RHEndPointModel *lcuEndpointModel;
@property (nonatomic ,strong) RHEndPointModel *dehumEndpointModel;
@property (nonatomic, strong) NSDate *meterDate;//电表采样时间

@property (nonatomic, strong) RHNavTitleView *titleView;
@property (nonatomic, assign) BOOL isFromEndpoint;//是否从部件列表进来
@end

@implementation RHDataMonitor233VC
-(instancetype)initWithEndpointModel:(RHEndPointModel*)endpointModel
{
    if (self = [super init]) {
        _curEndPointModel = endpointModel;
        self.isFromEndpoint = YES;
        self.titleView = [[RHNavTitleView alloc]init];
        [self.titleView hideArrowImg];
        self.navigationItem.titleView = self.titleView;
    }
    return self;
}

-(void)updateTitleView
{
    self.titleView.devNameLab.text = self.curDevModel.deviceName;
    self.titleView.devIdLab.text = self.curDevModel.deviceId;
    self.titleView.status = self.curDevModel.status;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:CFTabViewBgColor];
    [self updateTitleView];
    //tableView列表配置文件
    NSString *jsonFile = @"";
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"EMS"]) {
        jsonFile = @"he_ems_data";
    }
    
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"EMU"]) {
        jsonFile = @"me_emu_233_data";

        [self getMeterInfo];
        [self getMasterInfo];
        [self getLCUInfo];
        [self getDehumInfo];
    }
    
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"Master"]) {
        jsonFile = @"me_master_233_data";
    }
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"Pack"]) {
        jsonFile = @"me_pack_233_data";
        [self getDeviceInfo];
    }
    
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"InvVoltronicLv"]||
        [self.endPointTypeModel.endpointTypeCode isEqualToString:@"InvMegarevoLv"]) {
        jsonFile = @"he_inverter_data";//日月元
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"InvMegarevoLv"]){
            jsonFile = @"he_inverter_InvMegarevoLv_data";//麦格瑞能
        }
        //逆变器有的电池曲线参数是从EMU取的
        [self getEmuInfo];
    }
    
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"PcsKH"]) {
        jsonFile = @"me_pcs_data";
        //逆变器有的电池曲线参数是从EMU取的
        [self getEmuInfo];
    }
    //欧规
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"PcsYT"]) {
        jsonFile = @"me_pcs_233_EU_data";
       
    }
    //电表
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"MTR"]) {
        jsonFile = @"me_meter_data";
        self.meterDate = [NSDate date];
    }
   
    //液冷
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"LCU"]) {
        jsonFile = @"me_lcu_data";
    }
    
    //液冷
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"DHM"]) {
        jsonFile = @"me_dehum_233_data";
    }
    //根据端点类型模型创建曲线模型
    self.chartParamsModel = [DevChartTypeModel creatChartParams:ChartType_Master];
    self.chartParamsModel.chartList = @[];
    self.chartParamsModel.formFields = @[];
    NSArray *array = [SYChartTool loadJsonFileWithName:jsonFile];
    self.dataArray = [NSArray yy_modelArrayWithClass:[RHInverterModel class] json:array];
    
    //设备在线状态,sn  以及PACK储能信息
    if (self.isFromEndpoint||[self.endPointTypeModel.endpointTypeCode isEqualToString:@"Pack"]) {
        [self getDeviceInfo];
    }
    [self getParamList:self.endPointTypeModel.endpointTypeId];
    [self setupUI];
   
}


#pragma mark --------------- 1. 设置大端点类型 默认选择第一个个子端点进行获取数据点和曲线要显示的参数
-(void)setEndPointTypeModel:(RHEndPointTypeModel *)endPointTypeModel
{
    _endPointTypeModel = endPointTypeModel;
    if(endPointTypeModel.nodes.count>0){
        self.curEndPointModel = [endPointTypeModel.nodes firstObject];
    }
    BOOL is233 = [self.curDevModel.deviceTypeCode is233DeviceType];
    if ([self.endPointTypeModel.endpointTypeCode isEqualToString:@"Master"] && is233) {//233k才有电芯电压位置曲线
        [self createCellData];
        [self getPackInfoWithMaster:self.curEndPointModel.sn];
    }
}


#pragma mark --------------- 2. 选择子端点 获取要展示的参数-------
//选择大的类型
- (void)getParamList:(NSInteger)enpointTypeId
{
   
    kWeakSelf;
    //获取要显示的曲线和底部数据 参数
   
    NSDictionary *para = @{
        @"endpointTypeId": @(enpointTypeId),
        @"styles": @[@(1), @(2)],
        @"deviceTypeCode":self.curDevModel.deviceTypeCode
       };
    [DeviceChartFieldModel startWithCompletionAPIKey:H_getDataByStyle argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        NSArray *dataArr = resultModel.data;
        self.allFieldData = dataArr;
        NSMutableArray *chartDataArr = [NSMutableArray array];
        
        //默认加载的分析数据  (曲线)
        NSMutableArray *analysisKeys = [NSMutableArray array];
        NSString *fileName ;
        NSArray *defaultSelectKeys ;
       
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"EMS"]){
            fileName  = @"he_para_select_ems_custom";
            defaultSelectKeys = @[@"Ems_BCE_Day",@"Ems_BDE_Day",@"Ems_PPG_Day",@"Ems_DGPE_Day",@"Ems_GGE_Day",@"Ems_GPE_Day",@"Ems_LE_Day"];
        }
        //233k的用EMU
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"EMU"]){
            fileName  = @"me_para_select_emu_custom";
            defaultSelectKeys = @[@"Emu_BCE_Day",@"Emu_BDE_Day"];
        }
        
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"Master"]){
            
            fileName = @"me_para_select_master_233_custom";
            defaultSelectKeys = @[@"Mtr_Cur",@"Mtr_HT",@"Mtr_LT",@"Mtr_MaxPackDT",@"Mtr_Tmp_NTC2",@"Mtr_DsgPort_P_Tem",@"Mtr_DsgProt_N_Tem"];
        }
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"Pack"]){
            fileName  = @"me_para_select_pack_233_custom";
            defaultSelectKeys = @[@"Pck_Cur",@"Pck_HT",@"Pck_LT",@"Pck_Tmp_Mos",@"Pck_Tmp_Cnct",@"Pck_NegTemp",@"Pck_TempDiff"];

        }
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"PcsKH"]){//美规
            fileName  = @"me_para_select_pcs_Other";
            defaultSelectKeys = @[@"PcsKH_SystemApparentPower", @"PcsKH_SystemActivePower",@"PcsKH_SystemReactivePower"];
        }
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"PcsYT"]){//欧规
            fileName  = @"me_para_select_pcs_EU_custom";
            defaultSelectKeys = @[@"PcsYT_SysAcABVaildVol", @"PcsYT_SysAcBCVaildVol",@"PcsYT_SysAcCAVaildVol"];
        }
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"LCU"]){
            fileName  = @"me_para_select_lcu_233_custom";
            defaultSelectKeys = @[@"Lci_i16outTemp", @"Lci_i16retTemp",@"Lci_i16ambTemp",@"Lci_u16pumpSpeed"];
        }
        
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"DHM"]){
            fileName  = @"me_para_select_dehum_233_custom";
            defaultSelectKeys = @[@"dehum_InterTemprtVal", @"dehum_EnvirTemprtVal",@"dehum_ENvirHumVal"];
        }
        
        if([self.endPointTypeModel.endpointTypeCode isEqualToString:@"MTR"]){
            fileName  = @"me_para_select_meter_233_custom";
            defaultSelectKeys = @[@"GrSmmtr_ABLneVolt", @"GrSmmtr_CBLneVolt",@"GrSmmtr_ACLneVolt"];
        }
        NSLog(@"------>默认曲线的文件名:%@",fileName);
        NSArray *array = [SYChartTool loadJsonFileWithName:fileName];
        NSArray *modelArr = [NSArray yy_modelArrayWithClass:[RHInvParamModel class] json:array];
        [defaultSelectKeys enumerateObjectsUsingBlock:^(NSString *  _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
            [modelArr enumerateObjectsUsingBlock:^(RHInvParamModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [obj.rowArr enumerateObjectsUsingBlock:^(RHInvParamModel * _Nonnull row_obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    [row_obj.itemArr enumerateObjectsUsingBlock:^(RHInvParamModel * _Nonnull item_obj, NSUInteger idx, BOOL * _Nonnull stop) {
                        if ([item_obj.keyCode isEqualToString:key]) {
                            [analysisKeys addObject:item_obj.keyCode];
                        }
                    }];
                }];
            }];
        }];
        
        NSLog(@"----->默认显示的曲线字段:%@",analysisKeys);
        NSMutableArray *mtbArr = [NSMutableArray array];
        [dataArr enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([analysisKeys containsObject:obj.keyCode]) {
                [mtbArr addObject:obj];
            }
        }];
        chartDataArr = mtbArr;
        //找出所有单位
        NSMutableArray *unitArr = [NSMutableArray array];
        [chartDataArr enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull chartModel, NSUInteger idx, BOOL * _Nonnull stop) {
            if (![unitArr containsObject:chartModel.unitName]) {
                [unitArr addObject:chartModel.unitName];
            }
        }];
        self.unitCount = unitArr.count;
       
        NSMutableArray *chartListArr = [NSMutableArray array];
        //创建曲线模型
        DevChartModel *chartModel = [[DevChartModel alloc]init];
        chartModel.maxSelectCount = 20;//最大曲线条数
        chartModel.selectArray = chartDataArr;
        chartModel.dayParams = chartDataArr.copy;
        chartModel.monthParams = chartDataArr.copy;
        chartModel.yearParams = chartDataArr.copy;
        chartModel.params = chartDataArr.copy;
        chartModel.timeType = TimeType_Day;
        NSDate *date = [NSDate date];
        NSTimeInterval interval = [date timeIntervalSince1970];
        chartModel.curTime = [NSString stringWithFormat:@"%d",(int)interval];
        
        [chartListArr addObject:chartModel];
        
        

        [self.chartParamsModel setNetworkChartList: chartListArr.copy];
        
        //匹配本地json文件,将带有值的fieldModel存进模型
        
        [self macthLocalJsonFile];
        
        [self.tableView reloadData];
        
        [self getDeviceData];
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}



#pragma mark --------------- 3. 获取 数据点 数据 ----

- (void)getFormData{
    
    if(!self.curEndPointModel){
        [self.tableView endHeaderRefresh];
        return;
    }
    //只获取当前端点的参数
    NSString *prefixKey = [NSString getEndpointParaPrefixStringWithEndpointCode:self.curEndPointModel.endpointCode deviceTypeCode:self.curDevModel.deviceTypeCode];
    
    NSMutableArray *paraKey = [NSMutableArray array];
    
    //添加其他样式的参数点
    [self.dataArray enumerateObjectsUsingBlock:^(RHInverterModel*  _Nonnull model, NSUInteger idx, BOOL * _Nonnull stop) {
        [model.rowDataArr enumerateObjectsUsingBlock:^(RHInverterModel * _Nonnull row_obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [row_obj.itemArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([obj isKindOfClass:[NSArray class]]) {
                    NSArray *arr = obj;
                    [arr enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                        if (obj.keyCode && [obj.keyCode containsString:prefixKey]) {//只添加当前端点的参数
                            [paraKey addObject:obj.keyCode];
                        }
                    }];
                   
                }
                if ([obj isKindOfClass:[DeviceChartFieldModel class]]) {
                    DeviceChartFieldModel *fieldModel = (DeviceChartFieldModel*)obj;
                    if (fieldModel.keyCode && [fieldModel.keyCode containsString:prefixKey]) {//只添加当前端点的参数
                        [paraKey addObject:fieldModel.keyCode];
                    }
                }
            }];
        }];
        
        [model.itemArr enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull fileld, NSUInteger idx, BOOL * _Nonnull stop) {
            NSString *separateKey;
            if([fileld.keyCode containsString:@"*"]){
                separateKey = @"*";
            }
            if([fileld.keyCode containsString:@"/"]){
                separateKey = @"/";
            }
            if(separateKey){
                NSArray *keys = [fileld.keyCode componentsSeparatedByString:separateKey];
                NSString *key1 = [keys firstObject];
                NSString *key2 = [keys lastObject];
                if (key1 && ![paraKey containsObject:key1] && [key1 containsString:prefixKey]) {
                    [paraKey addObject:keys.firstObject];
                }
                if (key2 && ![paraKey containsObject:key2] && [key2 containsString:prefixKey]) {
                    [paraKey addObject:keys.lastObject];
                }
            }else{
                
                if ([fileld.keyCode containsString:prefixKey]) {
                    [paraKey addObject:fileld.keyCode];
                }
               
            }
        }];
    }];
    
    NSMutableDictionary *para = @{@"deviceId":self.curDevModel.deviceId,
                           @"endpointTypeCode":self.curEndPointModel.endpointCode,
                           @"keyCodes":paraKey,
                           @"endpointSn":self.curEndPointModel.sn
    }.mutableCopy;
    
    //如果是233电表数据
    if ([self.curEndPointModel.endpointCode isEqualToString:@"MTR"]) {
        NSDate *begin_date = [NSDate dateWithYear:self.meterDate.year month:self.meterDate.month day:self.meterDate.day hour:0 minute:0 second:0];
        NSDate *end_date = [NSDate dateWithYear:self.meterDate.year month:self.meterDate.month day:self.meterDate.day hour:23 minute:59 second:59];
        
        NSString *begin_time = [NSString stringWithFormat:@"%zd",(NSInteger)[begin_date timeIntervalSince1970]*1000];
        NSString *end_time = [NSString stringWithFormat:@"%zd",(NSInteger)[end_date timeIntervalSince1970]*1000];
        [para setObject:SafeStr(begin_time) forKey:@"currentBeginTime"];
        [para setObject:SafeStr(end_time) forKey:@"currentEndTime"];
    }
    [BaseModel startWithCompletionAPIKey:D_getLastEndpointData argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
        if(resultModel.code == 200){
            
            if([request.responseObject[@"data"] isKindOfClass:[NSDictionary class]]){
                NSDictionary *dic = request.responseObject[@"data"];
//                self.chartParamsModel.formFieldDataArray = @[dic];
                [self.allFieldData enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    
                    obj.content = dic[obj.keyCode];
                    
                    //对于Emu_MaxChgCur*Emu_TV字段的赋值
                    if([obj.keyCode containsString:@"*"]){
                        NSArray *keys = [obj.keyCode componentsSeparatedByString:@"*"];
                        NSString *key1 = [keys firstObject];
                        NSString *key2 = [keys lastObject];
                        if (dic[key1]&&dic[key2]) {
                            double value = [dic[key1] doubleValue] * [dic[key2] doubleValue];
                            obj.content = [NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:value];
                        }else{
                            obj.content = @"";
                        }
                       
                    }
                    
                    //对于Pcs_DCPowerU1/Pcs_ActivePwrU1(交流器效率)字段的赋值  根据充放电状态来除
                    if([obj.keyCode containsString:@"/"]){
                        NSArray *keys = [obj.keyCode componentsSeparatedByString:@"/"];
                        NSString *key1 = [keys firstObject];
                        NSString *key2 = [keys lastObject];
                        if (dic[key1]&&dic[key2]) {
                            if ([dic[key1] doubleValue] == 0||[dic[key2] doubleValue] == 0) {
                                obj.content = @"0";
                            }else{
                                if ([obj.keyCode isEqualToString:@"Pcs_DCPowerU1/Pcs_ActivePwrU1"]) {
                                    if (fabs([dic[key1] doubleValue])<fabs([dic[key2] doubleValue])) {
                                        double value = [dic[key1] doubleValue] / [dic[key2] doubleValue];
                                        obj.content = [NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:value];
                                    }else{
                                        double value = [dic[key2] doubleValue] / [dic[key1] doubleValue];
                                        obj.content = [NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:value];
                                    }
                                }else{
                                    double value = [dic[key1] doubleValue] / [dic[key2] doubleValue];
                                    obj.content = [NSDecimalNumber decimalPlacesWithRoundUpWithDigit:3 value:value];
                                }
                                
                                
                            }
                            
                        }else{
                            obj.content = @"0";
                        }
                       
                    }
                }];
                //EMU运行状态中有master参数
                [self macthLocalJsonFile];

                if ([self.curEndPointModel.endpointCode isEqualToString:@"MTR"]) {
                    NSInteger time = [dic[@"ts"] integerValue]/1000;
                    if (time > [[NSDate date]timeIntervalSince1970]||time == 0) {
//                        self.meterDate = [NSDate date];
                    }else{
                        self.meterDate = [NSDate dateWithTimeIntervalSince1970:time];
                    }
                    
                }
                [self.tableView reloadData];
            }
            
            
        }
       
        
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
    }];
}


#pragma mark --------------- 4.获取曲线数据 -----

- (void)getDataFromNetwork:(DevChartModel *)chartModel{
    
    if (!_curDevModel) {
        return;
    }
    
    NSMutableArray *keys = [NSMutableArray array];
    for (DeviceChartFieldModel *fileld in chartModel.selectArray) {
        [keys addObject:fileld.keyCode];
    }

    if (keys.count == 0) {
        return;
    }
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[chartModel.curTime integerValue]];
    NSDate *begin_date = [NSDate dateWithYear:date.year month:date.month day:date.day hour:0 minute:0 second:0];
    NSDate *end_date = [NSDate dateWithYear:date.year month:date.month day:date.day hour:23 minute:59 second:59];
    
    NSString *begin_time = [NSString stringWithFormat:@"%zd",(NSInteger)[begin_date timeIntervalSince1970]*1000];
    NSString *end_time = [NSString stringWithFormat:@"%zd",(NSInteger)[end_date timeIntervalSince1970]*1000];
    
    
    if(!self.curEndPointModel){
        NSLog(@"------->请选择子端点");
        [self.tableView endHeaderRefresh];
        return;
    }
    
    //将参数归类,有可能是两个端点类型的参数
    
    NSMutableDictionary *para = @{@"deviceId":self.curDevModel.deviceId,
                           @"endpointTypeCode":self.endPointTypeModel.endpointTypeCode,
                           @"keyCodes":keys,
                           @"endpointSn":self.curEndPointModel.sn,
                           @"startTimestamp":begin_time,
                           @"endTimestamp":end_time
    }.mutableCopy;
    
    //接口
    NSString *url = D_getEndpointDataByTime;
    
    if ([self.endPointTypeModel.endpointTypeCode containsString:@"InvVoltronicLv"]||
        [self.endPointTypeModel.endpointTypeCode containsString:@"InvMegarevoLv"]) {
        url = D_getInvEndpointDataByTime;
        
        NSMutableArray *emuKeys = [NSMutableArray array];
        NSMutableArray *invKeys = [NSMutableArray array];
        [keys enumerateObjectsUsingBlock:^(NSString*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj containsString:@"Inv"]) {
                [invKeys addObject:obj];
            }
            if ([obj containsString:@"Emu"]) {
                [emuKeys addObject:obj];
            }
        }];
        para = @{@"deviceId":self.curDevModel.deviceId,
                 @"startTimestamp":begin_time,
                 @"endTimestamp":end_time,
                 @"dateRange":@"day"
        }.mutableCopy;
        if (emuKeys.count>0) {
            [para setObject:ValidNullData(self.emuSN) forKey:@"emuSn"];
            [para setObject:emuKeys forKey:@"emuKeyCode"];
        }
        if (invKeys.count>0) {
            [para setObject:self.curEndPointModel.sn forKey:@"invSn"];
            [para setObject:invKeys forKey:@"invKeyCode"];
            [para setObject:self.curEndPointModel.endpointCode forKey:@"invEndpointCode"];//兼容以前的
        }
    }
    [QMUITips showLoadingInView:self.view];
    [BaseModel startWithCompletionAPIKey:url argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
        if(resultModel.code == 200){
            if([request.responseObject[@"data"] isKindOfClass:[NSArray class]]){
                NSArray *dataArr = request.responseObject[@"data"];
                
                chartModel.allDataArray = dataArr;

                [self reloadTableCell];
            }
        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
        
    }];
}

#pragma mark --------------- 匹配本地json文件里的key ,如运行数据,电池簇数据
//这里有个问题:在当前端点参数中如果存在其他的端点的参数时,因为获取端点参数(后接着获取参数值)是异步的,这就有可能会把之前请求较快要的数据给刷掉
-(void)macthLocalJsonFile
{
    NSMutableArray *paraArr = [NSMutableArray array];
    [paraArr addObjectsFromArray:self.allFieldData];
    [paraArr addObjectsFromArray:self.pcsFieldData];
    [paraArr addObjectsFromArray:self.meterFieldData];
    [paraArr addObjectsFromArray:self.masterFieldData];
    [paraArr addObjectsFromArray:self.lcuFieldData];
    [paraArr addObjectsFromArray:self.dehumFieldData];
    
    [self.dataArray enumerateObjectsUsingBlock:^(RHInverterModel*  _Nonnull invSectionModel, NSUInteger idx, BOOL * _Nonnull stop) {
        [invSectionModel.rowDataArr enumerateObjectsUsingBlock:^(RHInverterModel * _Nonnull rowModel, NSUInteger idx, BOOL * _Nonnull stop) {
            NSMutableArray *mtbArr = [NSMutableArray array];
            //有一维数组和二维数组两种情况
            [rowModel.rowKeys enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                //一维数组
                if ([obj isKindOfClass:[NSString class]]) {
                    [paraArr enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull fieldModel, NSUInteger idx, BOOL * _Nonnull stop) {
                        if ([obj isEqualToString:fieldModel.keyCode]) {
                            [mtbArr addObject:fieldModel];
                        }
                    }];
                }
               
                //二维数组
                if ([obj isKindOfClass:[NSArray class]]) {
                    NSArray *keyArr = obj;
                    NSMutableArray *subMtbArr = [NSMutableArray array];
                    [keyArr enumerateObjectsUsingBlock:^(id  _Nonnull obj2, NSUInteger idx, BOOL * _Nonnull stop) {
                        [paraArr enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull fieldModel_2, NSUInteger idx, BOOL * _Nonnull stop) {
                            if ([obj2 isEqualToString:fieldModel_2.keyCode]) {
                                [subMtbArr addObject:fieldModel_2];
                            }
                        }];
                    }];
                    [mtbArr addObject:subMtbArr];
                }
            }];
            
            rowModel.itemArr = mtbArr.copy;
        }];
        
        
        NSMutableArray *rowDataArr = [NSMutableArray array];
        [invSectionModel.rowKeys enumerateObjectsUsingBlock:^(NSString*  _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
            [paraArr enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull fieldModel, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([key isEqualToString:fieldModel.keyCode]) {
                    [rowDataArr addObject:fieldModel];
                }
            }];
        }];
        if (rowDataArr) {
            invSectionModel.itemArr = rowDataArr.copy;
        }
        
    }];
    
    
   
}

-(BOOL)containFieldModel:(NSArray*)itemArr
{
    BOOL result = NO;
    [itemArr enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull fieldModel, NSUInteger idx, BOOL * _Nonnull stop) {
         
    }];
    return result;
}



#pragma mark --------------- 更新端点下的子端点在线状态
-(void)updateEndpointTypeModel:(RHEndPointTypeModel*)typeModel
{
    if (self.endPointTypeModel.endpointTypeId == typeModel.endpointTypeId) {
        [self.endPointTypeModel.nodes enumerateObjectsUsingBlock:^(RHEndPointModel * _Nonnull model, NSUInteger idx, BOOL * _Nonnull stop) {
            [typeModel.nodes enumerateObjectsUsingBlock:^(RHEndPointModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([model.sn isEqualToString:obj.sn]) {
                    model.state = obj.state;
                }
            }];
        }];
    }
    self.headerView.endPointModel = self.headerView.endPointModel;
}

#pragma mark ---------- 刷新端点下的子端点信息
-(void)getSubEndpointListInfo
{
    if (self.curDevModel.deviceId.length == 0 || self.endPointTypeModel.endpointTypeCode.length==0) {
        return;
    }
    NSDictionary *para = @{@"deviceId":self.curDevModel.deviceId,@"endpointCode":self.endPointTypeModel.endpointTypeCode};
    [RHEndPointModel startGetWithCompletionAPIKey:H_getEndpointListByCode argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if (resultModel.code == 200) {
            NSArray *endpointArr = resultModel.data;
            self.endPointTypeModel.nodes = endpointArr;
            [self.endPointTypeModel.nodes enumerateObjectsUsingBlock:^(RHEndPointModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([obj.sn isEqualToString:self.curEndPointModel.sn]) {
                    self.curEndPointModel = obj;
                    self.headerView.endPointModel = self.curEndPointModel;
                }
            }];
        }
        } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
            
        }];
}

#pragma mark ------ 获取设备信息(topo数据,有无可升级固件,储能状态)
-(void)getDeviceInfo
{
    [QMUITips showLoadingInView:self.view];
    NSString *url = [NSString stringWithFormat:@"%@%ld",H_getDeviceInfo,self.curDevModel.device_id];
    [RHTopoModel startGetWithCompletionAPIKey:url argument:@{} requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
            RHTopoModel *topoModel = resultModel.data;
            self.headerView.topoModel = topoModel;
            [self.tableView endHeaderRefresh];
            self.curDevModel.status = topoModel.status;
            [self updateTitleView];
        }
        
        } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
                
        }];
}

#pragma mark -----  Action
- (void)fullAction:(NSInteger)index{
    DevChartModel *chartModel = self.chartParamsModel.chartList[index];
    NSInteger type = 2;
//    if (chartModel.monthParams.count>0) {
//        type = 1;
//    }
//    if (chartModel.yearParams.count>0) {
//        type = 0;
//    }
    
    DevChartModel *fullModel = [chartModel modelCopy];
    DeviceFullChartController *vc = [[DeviceFullChartController alloc] initWithModel:fullModel devModel:self.curDevModel chartType:self.chartParamsModel.type toolType:type endPointModel:self.curEndPointModel];
    vc.emuSN = self.emuSN;
    vc.endpointType = self.endPointTypeModel.endpointTypeCode;
    [self.navigationController pushViewController:vc animated:NO];
}

#pragma mark ----- 参数 , 年 , 月 , 日选项 -------------
//工具选择项
- (void)selectTopTool:(NSInteger)index atIndexpath:(NSIndexPath *)indexpath{
    DevChartModel *chartModel = self.chartParamsModel.chartList[indexpath.row];
    
    if (index == -1) {//Params
        
        [self.paraSelectView showInWindowAnimate];
    
//        return;
//
//
//        DevParamsAlertController *vc = [[DevParamsAlertController alloc] initWithModel:chartModel isFull:NO maxSelectCount:chartModel.maxSelectCount];
//        [[RHWindowTipManage shareWindowTipManage] showWithController:vc];
//
//        vc.resultBlock = ^{
//            [weakSelf updateParams:chartModel];
//        };
//        return;
    }

    if (index == 0) {//Day
        chartModel.timeType = TimeType_Day;
        NSDate *date = [NSDate date];
        NSTimeInterval interval = [date timeIntervalSince1970];
        chartModel.curTime = [NSString stringWithFormat:@"%d",(int)interval];
        chartModel.params = chartModel.dayParams;
        [self getDataFromNetwork:chartModel];
        return;
    }
    
    if (index == 1) {//Month
        chartModel.timeType = TimeType_Month;
        NSDate *date = [NSDate date];
        NSTimeInterval interval = [date timeIntervalSince1970];
        chartModel.curTime = [NSString stringWithFormat:@"%d",(int)interval];
        chartModel.params = chartModel.monthParams;
        chartModel.allDataArray = @[];
        [self reloadTableCell];
//        [self getYearOrMonth:YES model:chartModel];
        return;
    }
    
    if (index == 2) {//Year
        chartModel.timeType = TimeType_Year;
        NSDate *date = [NSDate date];
        NSTimeInterval interval = [date timeIntervalSince1970];
        chartModel.curTime = [NSString stringWithFormat:@"%d",(int)interval];
        chartModel.params = chartModel.yearParams;
        chartModel.allDataArray = @[];;
        [self reloadTableCell];
//        [self getYearOrMonth:NO model:chartModel];
        return;
    }
    
    if (index == 4) {//Total
        chartModel.timeType = TimeType_Total;
        return;
    }

    
}
#pragma mark ------ 选择日期 ------
//变更日期
- (void)changeDate:(NSIndexPath *)indexpath{
    DevChartModel *chartModel = self.chartParamsModel.chartList[indexpath.row];
    //NSString *dateFormatStr = @"yyyy-MM-dd HH:mm";
    WSDateStyle dataStyle = DateStyleShowYearMonthDay;
    if (chartModel.timeType == TimeType_Day) {
        dataStyle = DateStyleShowYearMonthDay;
    }else if (chartModel.timeType == TimeType_Month){
        dataStyle = DateStyleShowYearMonth;
    }else if (chartModel.timeType == TimeType_Year){
        dataStyle = DateStyleShowYearMonthDay;
    }

    @weakify(self);
    WSDatePickerView *datePickerV = [[WSDatePickerView alloc] initWithDateStyle:dataStyle CompleteBlock:^(NSDate *selectDate) {
        @strongify(self);
        //NSString *currentDate = [selectDate stringWithFormat: dateFormatStr];//年-月-日-时-分
        NSUInteger timeSp = [selectDate timeIntervalSince1970];
        chartModel.curTime = [NSString stringWithFormat:@"%d",(int)timeSp];
        if (chartModel.timeType == TimeType_Day) {
            [self getDataFromNetwork:chartModel];
        }else if (chartModel.timeType == TimeType_Month){
//            [self getYearOrMonth:YES model:chartModel];
            [self reloadTableCell];
        }else if (chartModel.timeType == TimeType_Year){
//            [self getYearOrMonth:NO model:chartModel];
            [self reloadTableCell];
        }
    }];
    datePickerV.dateLabelColor = FontColor(@"#3ECE80");//年-月 颜色
    datePickerV.datePickerColor = UIColorBlack;//滚轮日期颜色
    datePickerV.doneButtonColor = UIColor.blackColor;//确定按钮的颜色
    if (chartModel.timeType == TimeType_Day) {
        datePickerV.maxLimitDate = [NSDate date];
        datePickerV.minLimitDate = [NSDate dateWithYear:[NSDate date].year-5 month:[NSDate date].month day:[NSDate date].day hour:[NSDate date].hour minute:[NSDate date].minute second:[NSDate date].second];
    }else if (chartModel.timeType == TimeType_Month){

    }else if (chartModel.timeType == TimeType_Year){
        datePickerV.maxLimitDate = [NSDate date];
        datePickerV.minLimitDate = [NSDate dateWithYear:[NSDate date].year-5 month:[NSDate date].month day:[NSDate date].day hour:[NSDate date].hour minute:[NSDate date].minute second:[NSDate date].second];
    }
    [datePickerV show];
}
#pragma mark ------ 前一天 -------
//日期累加
- (void)addTimeAction:(NSIndexPath *)indexpath{
    DevChartModel *chartModel = self.chartParamsModel.chartList[indexpath.row];
    if (chartModel.timeType == TimeType_Total) {
        return;
    }
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[chartModel.curTime integerValue]];
    NSDate *nextDate;
    if (chartModel.timeType == TimeType_Day) {
        nextDate = [date dateByAddingDays:1];
    }else if (chartModel.timeType == TimeType_Month){
        nextDate = [date dateByAddingMonths:1];
    }else if (chartModel.timeType == TimeType_Year){
        nextDate = [date dateByAddingYears:1];
    }
    NSTimeInterval interval = [nextDate timeIntervalSince1970];
    chartModel.curTime = [NSString stringWithFormat:@"%d",(int)interval];
    
    if (chartModel.timeType == TimeType_Day) {
        [self getDataFromNetwork:chartModel];
    }else if (chartModel.timeType == TimeType_Month){
       
        [self reloadTableCell];
    }else if (chartModel.timeType == TimeType_Year){
       
    }
}

#pragma mark ------ 后一天 -------
//日期累减
- (void)subTimeAction:(NSIndexPath *)indexpath{
    DevChartModel *chartModel = self.chartParamsModel.chartList[indexpath.row];
    if (chartModel.timeType == TimeType_Total) {
        return;
    }
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[chartModel.curTime integerValue]];
    NSDate *nextDate;
    if (chartModel.timeType == TimeType_Day) {
        nextDate = [date dateBySubtractingDays:1];
    }else if (chartModel.timeType == TimeType_Month){
        nextDate = [date dateBySubtractingMonths:1];
    }else if (chartModel.timeType == TimeType_Year){
        nextDate = [date dateBySubtractingYears:1];
    }
    NSTimeInterval interval = [nextDate timeIntervalSince1970];
    chartModel.curTime = [NSString stringWithFormat:@"%d",(int)interval];
    
    if (chartModel.timeType == TimeType_Day) {
        [self getDataFromNetwork:chartModel];
    }else if (chartModel.timeType == TimeType_Month){
        
    }else if (chartModel.timeType == TimeType_Year){
        
    }
}




-(void)getDeviceData
{
    //设置曲线参数
    [self.chartParamsModel.chartList enumerateObjectsUsingBlock:^(DevChartModel  *_Nonnull chartModel, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if (self.curDevModel) {
            if (chartModel.timeType == TimeType_Day) {
                [self getDataFromNetwork:chartModel];
            }else if (chartModel.timeType == TimeType_Month){
              
            }else if (chartModel.timeType == TimeType_Year){
                
            }
        }else{
            [self reloadTableCell];
        }
    }];
    
    if (self.curDevModel) {
        //获取底部数据
        [self getFormData];

    }

}



#pragma mark - Action Mothed
- (void)updateParams:(DevChartModel *)chartModel{
    
    if (chartModel.timeType == TimeType_Day) {
        [self getDataFromNetwork:chartModel];
    }else if (chartModel.timeType == TimeType_Month){
      
    }else if (chartModel.timeType == TimeType_Year){
       
    }
}

//手动更新Cell
- (void)reloadTableCell{
    /*[self.chartParamsModel.chartList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        DeviceCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:0]];
        [cell setChartModel:obj];
    }];*/
    [self.tableView reloadData];
}



- (void)firmwareUpgradeAction{
    RHFirmwareListVC *vc = [[RHFirmwareListVC alloc] init];
    vc.deviceModel = self.curDevModel;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark ----- 更多数据点(原来的数据点)
-(void)seeFieldData:(RHInverterModel*)model
{
    RHFieldsDataVC *vc = [[RHFieldsDataVC alloc]initWithEndpointModel:self.curEndPointModel deviceModel:self.curDevModel];
    vc.title = model.title.rh_localized;
    vc.formFields = model.itemArr;
    if (self.masterFieldData) {
        vc.masterEndpointModel = self.masterEndpointModel;
    }
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark ----- 更多数据点(新增)
-(void)seeOtherData:(RHInverterModel*)model
{
    //电池簇数据
    RHOtherFieldsDataVC *fieldVC = [[RHOtherFieldsDataVC alloc]initWithEndpointModel:self.curEndPointModel
                                                                         deviceModel:self.curDevModel];
    fieldVC.title = model.title.rh_localized;
    fieldVC.formFields = model.itemArr;
    fieldVC.pcsEndpointModel   = self.pcsEndpointModel;
    fieldVC.meterEndpointModel = self.meterEndpointModel;
    fieldVC.lcuEndpointModel   = self.lcuEndpointModel;
    fieldVC.dehumEndpointModel   = self.dehumEndpointModel;
    [self.navigationController pushViewController:fieldVC animated:YES];
    
}
#pragma mark ------ 根据选择的参数重新组合曲线
-(void)combineData:(NSArray*)ModelArr
{
    
    //找出对应的deviceFieldModel
    NSMutableArray *chartModelArr = [NSMutableArray array];
    [ModelArr enumerateObjectsUsingBlock:^(RHInvParamModel*  _Nonnull invModel, NSUInteger idx, BOOL * _Nonnull stop) {
        NSLog(@"--------->查找参数%ld: %@ %@",idx+1,invModel.keyCode,invModel.keyName);
        [self.allFieldData enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull fieldModel, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([invModel.keyCode isEqualToString:fieldModel.keyCode]) {
                NSLog(@"---->找到参数:%@",fieldModel.keyCode);
                [chartModelArr addObject:fieldModel];
            }
        }];
    }];
    
    //如果是emu参数,去emu参数点里找
    [ModelArr enumerateObjectsUsingBlock:^(RHInvParamModel*  _Nonnull invModel, NSUInteger idx, BOOL * _Nonnull stop) {
        [self.emuFieldData enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull fieldModel, NSUInteger idx, BOOL * _Nonnull stop) {
            NSLog(@"--------->查找EMU参数%ld: %@ %@",idx+1,invModel.keyCode,invModel.keyName);
            if ([invModel.keyCode isEqualToString:fieldModel.keyCode]) {
                NSLog(@"---->找到EMU参数:%@",fieldModel.keyCode);
                [chartModelArr addObject:fieldModel];
            }
        }];
    }];
   
    //找出所有单位
    NSMutableArray *unitArr = [NSMutableArray array];
    [chartModelArr enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull chartModel, NSUInteger idx, BOOL * _Nonnull stop) {
        if (![unitArr containsObject:chartModel.unitName]) {
            [unitArr addObject:chartModel.unitName];
        }
    }];
    self.unitCount = unitArr.count;
    
    NSMutableArray *chartListArr = [NSMutableArray array];
    //创建曲线模型
    DevChartModel *chartModel = [[DevChartModel alloc]init];
    chartModel.maxSelectCount = 20;
    chartModel.selectArray = chartModelArr;
    chartModel.dayParams = chartModelArr.copy;
    chartModel.monthParams = chartModelArr.copy;
    chartModel.yearParams = chartModelArr.copy;
    chartModel.params = chartModelArr.copy;
    chartModel.timeType = TimeType_Day;
    NSDate *date = [NSDate date];
    NSTimeInterval interval = [date timeIntervalSince1970];
    chartModel.curTime = [NSString stringWithFormat:@"%d",(int)interval];
    
    [chartListArr addObject:chartModel];
  
    self.chartParamsModel.chartList = chartListArr;
    
    [self.chartParamsModel setNetworkChartList: chartListArr.copy];
    [self.tableView reloadData];
    
    //获取每个图表的曲线数据
    [self.chartParamsModel.chartList enumerateObjectsUsingBlock:^(DevChartModel  *_Nonnull chartModel, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if (self.curDevModel) {
            if (chartModel.timeType == TimeType_Day) {
                [self getDataFromNetwork:chartModel];
            }else if (chartModel.timeType == TimeType_Month){
              
            }else if (chartModel.timeType == TimeType_Year){
                
            }
        }else{
            [self reloadTableCell];
        }
    }];
}

#pragma mark ------1. 如果参数包含EMU,先拿SN 再拿数据 ---------
-(void)getEmuInfo
{
    [QMUITips showLoadingInView:self.view];
       NSDictionary *para = @{@"deviceId":ValidNullData(self.curDevModel.deviceId),
                              @"endpointTypeCode":@[@"EMU"],
                              @"group":@(1)};
    [RHEndPointModel startWithCompletionAPIKey:H_getEndpointByType argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
        
            if([request.responseJSONObject[@"data"] isKindOfClass:[NSArray class]]){
                NSArray *dataArr = request.responseJSONObject[@"data"];
                NSDictionary *dataDic = [dataArr firstObject];
                if([dataDic[@"endpointList"] isKindOfClass:[NSArray class]]){
                    NSArray *endPointArr = dataDic[@"endpointList"];
                    NSDictionary *endpointDic = [endPointArr firstObject];
                    self.emuSN = endpointDic[@"sn"];
                    [self getEMUParamList:[endpointDic[@"endpointTypeId"] integerValue]];
                }
            }

        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
        
    }];
}

#pragma mark ----2. 获取EMU模块参数
- (void)getEMUParamList:(NSInteger)enpointTypeId
{
    NSDictionary *para = @{
        @"endpointTypeId": @(enpointTypeId),
        @"styles": @[@(1), @(2)],
        @"deviceTypeCode":self.curDevModel.deviceTypeCode
       };
    [DeviceChartFieldModel startWithCompletionAPIKey:H_getDataByStyle argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        self.emuFieldData = resultModel.data;
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}

#pragma mark ------1. 233 Master参数信息中包含了pcs的数据点 ---------
-(void)getPcsInfo
{
    [QMUITips showLoadingInView:self.view];
       NSDictionary *para = @{@"deviceId":ValidNullData(self.curDevModel.deviceId),
                              @"endpointTypeCode":@[@"PcsKH"],
                              @"group":@(1)};
    [RHEndPointModel startWithCompletionAPIKey:H_getEndpointByType argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
        
            if([request.responseJSONObject[@"data"] isKindOfClass:[NSArray class]]){
                NSArray *dataArr = request.responseJSONObject[@"data"];
                NSDictionary *dataDic = [dataArr firstObject];
                if([dataDic[@"endpointList"] isKindOfClass:[NSArray class]]){
                    NSArray *endPointArr = [NSArray yy_modelArrayWithClass:[RHEndPointModel class] json:dataDic[@"endpointList"]];
                    RHEndPointModel *pcsModel = [endPointArr firstObject];
                    if (pcsModel) {
                        self.pcsEndpointModel = pcsModel;
                        [self getPcsParamList:pcsModel.endpointTypeId];
                    }
                    
                }
            }

        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
        
    }];
}
#pragma mark ----2. 获取PCS模块参数
- (void)getPcsParamList:(NSInteger)enpointTypeId
{
    NSDictionary *para = @{
        @"endpointTypeId": @(enpointTypeId),
        @"styles": @[@(1), @(2)],
        @"deviceTypeCode":self.curDevModel.deviceTypeCode
       };
    [DeviceChartFieldModel startWithCompletionAPIKey:H_getDataByStyle argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        self.pcsFieldData = resultModel.data;
        [self macthLocalJsonFile];
        [self.tableView reloadData];
        [self getPcsFormFieldData];
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}

#pragma mark -------3. 获取master参数信息中的pcs数据点 ----------
-(void)getPcsFormFieldData
{
    if (!self.pcsEndpointModel) {
        return;
    }
    //其他参数
    NSMutableArray *paraKey = [NSMutableArray array];
    [self.dataArray enumerateObjectsUsingBlock:^(RHInverterModel*  _Nonnull invSectionModel, NSUInteger idx, BOOL * _Nonnull stop) {
        [invSectionModel.rowDataArr enumerateObjectsUsingBlock:^(RHInverterModel * _Nonnull rowModel, NSUInteger idx, BOOL * _Nonnull stop) {
            //有一维数组和二维数组两种情况
            [rowModel.rowKeys enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                //一维数组
                if ([obj isKindOfClass:[NSString class]]) {
                    if ([obj hasPrefix:@"Pcs_"]) {
                        [paraKey addObject:obj];
                    }
                }
            }];
            
           
        }];
        
        [invSectionModel.rowKeys enumerateObjectsUsingBlock:^(NSString*  _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([key hasPrefix:@"Pcs_"]) {
                [paraKey addObject:key];
            }
            
        }];

    }];
    
    
    if (paraKey.count == 0) {
        return;
    }
    NSDictionary *para = @{@"deviceId":self.curDevModel.deviceId,
                           @"endpointTypeCode":SafeStr(self.pcsEndpointModel.endpointCode),
                           @"keyCodes":paraKey,
                           @"endpointSn":SafeStr(self.pcsEndpointModel.sn)
    };
    [BaseModel startWithCompletionAPIKey:D_getLastEndpointData argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
        if(resultModel.code == 200){
            NSDictionary *dic;
            if ([request.responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
                dic = request.responseObject[@"data"];
            }
            
            [self.chartParamsModel.formFields enumerateObjectsUsingBlock:^(DeviceChartFieldModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            
            [self.pcsFieldData enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            //将参数值合并到model中
            [self macthLocalJsonFile];
            [self.tableView reloadData];
        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
    }];
}

#pragma mark ------1. 233 EMU参数信息中包含了Meter的数据点 ---------
-(void)getMeterInfo
{
    [QMUITips showLoadingInView:self.view];
       NSDictionary *para = @{@"deviceId":ValidNullData(self.curDevModel.deviceId),
                              @"endpointTypeCode":@[@"MTR"],
                              @"group":@(1)};
    [RHEndPointModel startWithCompletionAPIKey:H_getEndpointByType argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
        
            if([request.responseJSONObject[@"data"] isKindOfClass:[NSArray class]]){
                NSArray *dataArr = request.responseJSONObject[@"data"];
                NSDictionary *dataDic = [dataArr firstObject];
                if([dataDic[@"endpointList"] isKindOfClass:[NSArray class]]){
                    NSArray *endPointArr = [NSArray yy_modelArrayWithClass:[RHEndPointModel class] json:dataDic[@"endpointList"]];
                    RHEndPointModel *meterModel = [endPointArr firstObject];
                    if (meterModel) {
                        self.meterEndpointModel = meterModel;
                        [self getMeterParamList:meterModel.endpointTypeId];
                    }
                    
                }
            }

        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
        
    }];
}

#pragma mark ----2. 获取Meter模块参数
- (void)getMeterParamList:(NSInteger)enpointTypeId
{
    NSDictionary *para = @{
        @"endpointTypeId": @(enpointTypeId),
        @"styles": @[@(1), @(2)],
        @"deviceTypeCode":self.curDevModel.deviceTypeCode
       };
    [DeviceChartFieldModel startWithCompletionAPIKey:H_getDataByStyle argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        self.meterFieldData = resultModel.data;
        //匹配文件里的key
        [self macthLocalJsonFile];
        //读取参数值
        [self getMeterFormFieldData];
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}

#pragma mark -------3. 获取EMU参数信息中的电表数据点 ----------
-(void)getMeterFormFieldData
{
    if (!self.meterEndpointModel) {
        return;
    }
    //电表参数
    NSMutableArray *paraKey = [NSMutableArray array];
    [self.dataArray enumerateObjectsUsingBlock:^(RHInverterModel*  _Nonnull invSectionModel, NSUInteger idx, BOOL * _Nonnull stop) {
        [invSectionModel.rowDataArr enumerateObjectsUsingBlock:^(RHInverterModel * _Nonnull rowModel, NSUInteger idx, BOOL * _Nonnull stop) {
            //有一维数组和二维数组两种情况
            [rowModel.rowKeys enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                //一维数组
                if ([obj isKindOfClass:[NSString class]]) {
                    if ([obj hasPrefix:@"GrSmmtr_"]) {
                        [paraKey addObject:obj];
                    }
                }
            }];
            
           
        }];
        
        [invSectionModel.rowKeys enumerateObjectsUsingBlock:^(NSString*  _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([key hasPrefix:@"GrSmmtr_"]) {
                [paraKey addObject:key];
            }
            
        }];

    }];
    NSDictionary *para = @{@"deviceId":self.curDevModel.deviceId,
                           @"endpointTypeCode":SafeStr(self.meterEndpointModel.endpointCode),
                           @"keyCodes":paraKey,
                           @"endpointSn":SafeStr(self.meterEndpointModel.sn)
    };
    [BaseModel startWithCompletionAPIKey:D_getLastEndpointData argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
        if(resultModel.code == 200){
            NSDictionary *dic;
            if ([request.responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
                dic = request.responseObject[@"data"];
            }
            
            [self.chartParamsModel.formFields enumerateObjectsUsingBlock:^(DeviceChartFieldModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            
            [self.meterFieldData enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            //将参数值合并到model中
            [self macthLocalJsonFile];
            [self.tableView reloadData];
        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
    }];
}

#pragma mark ------1. 233 EMU运行数据中包含了Master的数据点 ---------
-(void)getMasterInfo
{
    [QMUITips showLoadingInView:self.view];
       NSDictionary *para = @{@"deviceId":ValidNullData(self.curDevModel.deviceId),
                              @"endpointTypeCode":@[@"Master"],
                              @"group":@(1)};
    [RHEndPointModel startWithCompletionAPIKey:H_getEndpointByType argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
        
            if([request.responseJSONObject[@"data"] isKindOfClass:[NSArray class]]){
                NSArray *dataArr = request.responseJSONObject[@"data"];
                NSDictionary *dataDic = [dataArr firstObject];
                if([dataDic[@"endpointList"] isKindOfClass:[NSArray class]]){
                    NSArray *endPointArr = [NSArray yy_modelArrayWithClass:[RHEndPointModel class] json:dataDic[@"endpointList"]];
                    RHEndPointModel *masterModel = [endPointArr firstObject];
                    if (masterModel) {
                        self.masterEndpointModel = masterModel;
                        [self getMasterParamList:masterModel.endpointTypeId];
                    }
                    
                }
            }

        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
        
    }];
}

#pragma mark ----2. 获取Master模块参数
- (void)getMasterParamList:(NSInteger)enpointTypeId
{
    NSDictionary *para = @{
        @"endpointTypeId": @(enpointTypeId),
        @"styles": @[@(1), @(2)],
        @"deviceTypeCode":self.curDevModel.deviceTypeCode
       };
    [DeviceChartFieldModel startWithCompletionAPIKey:H_getDataByStyle argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        self.masterFieldData = resultModel.data;
        //匹配文件里的key
        [self macthLocalJsonFile];
        //读取参数值
        [self getMasterFormFieldData];
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}

#pragma mark -------3. 获取EMU运行数据中的master数据点 ----------
-(void)getMasterFormFieldData
{
    if (!self.masterEndpointModel) {
        return;
    }
    //电表参数
    NSMutableArray *paraKey = [NSMutableArray array];
    [self.dataArray enumerateObjectsUsingBlock:^(RHInverterModel*  _Nonnull invSectionModel, NSUInteger idx, BOOL * _Nonnull stop) {
        [invSectionModel.rowDataArr enumerateObjectsUsingBlock:^(RHInverterModel * _Nonnull rowModel, NSUInteger idx, BOOL * _Nonnull stop) {
            //有一维数组和二维数组两种情况
            [rowModel.rowKeys enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                //一维数组
                if ([obj isKindOfClass:[NSString class]]) {
                    if ([obj hasPrefix:@"Mtr_"]) {
                        [paraKey addObject:obj];
                    }
                }
            }];
            
           
        }];
        
        [invSectionModel.rowKeys enumerateObjectsUsingBlock:^(NSString*  _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([key hasPrefix:@"Mtr_"]) {
                [paraKey addObject:key];
            }
            
        }];

    }];
    NSDictionary *para = @{@"deviceId":self.curDevModel.deviceId,
                           @"endpointTypeCode":SafeStr(self.masterEndpointModel.endpointCode),
                           @"keyCodes":paraKey,
                           @"endpointSn":SafeStr(self.masterEndpointModel.sn)
    };
    [BaseModel startWithCompletionAPIKey:D_getLastEndpointData argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
        if(resultModel.code == 200){
            
            NSDictionary *dic;
            if ([request.responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
                dic = request.responseObject[@"data"];
            }
            
            [self.chartParamsModel.formFields enumerateObjectsUsingBlock:^(DeviceChartFieldModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            
            [self.masterFieldData enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            //将参数值合并到model中
            [self macthLocalJsonFile];
            [self.tableView reloadData];
        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
    }];
}

#pragma mark ------1. 233 EMU参数信息中包含了液冷的数据点 ---------
-(void)getLCUInfo
{
    [QMUITips showLoadingInView:self.view];
       NSDictionary *para = @{@"deviceId":ValidNullData(self.curDevModel.deviceId),
                              @"endpointTypeCode":@[@"LCU"],
                              @"group":@(1)};
    [RHEndPointModel startWithCompletionAPIKey:H_getEndpointByType argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
        
            if([request.responseJSONObject[@"data"] isKindOfClass:[NSArray class]]){
                NSArray *dataArr = request.responseJSONObject[@"data"];
                NSDictionary *dataDic = [dataArr firstObject];
                if([dataDic[@"endpointList"] isKindOfClass:[NSArray class]]){
                    NSArray *endPointArr = [NSArray yy_modelArrayWithClass:[RHEndPointModel class] json:dataDic[@"endpointList"]];
                    RHEndPointModel *lcuModel = [endPointArr firstObject];
                    if (lcuModel) {
                        self.lcuEndpointModel = lcuModel;
                        [self getLcuParamList:lcuModel.endpointTypeId];
                    }
                    
                }
            }

        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
        
    }];
}

#pragma mark ----2. 获取 LCU 模块参数
- (void)getLcuParamList:(NSInteger)enpointTypeId
{
    NSDictionary *para = @{
        @"endpointTypeId": @(enpointTypeId),
        @"styles": @[@(1), @(2)],
        @"deviceTypeCode":self.curDevModel.deviceTypeCode
       };
    [DeviceChartFieldModel startWithCompletionAPIKey:H_getDataByStyle argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        self.lcuFieldData = resultModel.data;
        //匹配文件里的key
        [self macthLocalJsonFile];
        //读取参数值
        [self getLcuFormFieldData];
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}

#pragma mark -------3. 获取EMU运行数据中的 LCU 数据点 ----------
-(void)getLcuFormFieldData
{
    if (!self.lcuEndpointModel) {
        return;
    }
    //电表参数
    NSMutableArray *paraKey = [NSMutableArray array];
    [self.dataArray enumerateObjectsUsingBlock:^(RHInverterModel*  _Nonnull invSectionModel, NSUInteger idx, BOOL * _Nonnull stop) {
        [invSectionModel.rowDataArr enumerateObjectsUsingBlock:^(RHInverterModel * _Nonnull rowModel, NSUInteger idx, BOOL * _Nonnull stop) {
            //有一维数组和二维数组两种情况
            [rowModel.rowKeys enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                //一维数组
                if ([obj isKindOfClass:[NSString class]]) {
                    if ([obj hasPrefix:@"Lci_"]) {
                        [paraKey addObject:obj];
                    }
                }
            }];
            
           
        }];
        
        [invSectionModel.rowKeys enumerateObjectsUsingBlock:^(NSString*  _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([key hasPrefix:@"Lci_"]) {
                [paraKey addObject:key];
            }
            
        }];

    }];
    if (paraKey.count==0) return;
    NSDictionary *para = @{@"deviceId":self.curDevModel.deviceId,
                           @"endpointTypeCode":SafeStr(self.lcuEndpointModel.endpointCode),
                           @"keyCodes":paraKey,
                           @"endpointSn":SafeStr(self.lcuEndpointModel.sn)
    };
    [BaseModel startWithCompletionAPIKey:D_getLastEndpointData argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
        if(resultModel.code == 200){
            
            NSDictionary *dic;
            if ([request.responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
                dic = request.responseObject[@"data"];
            }
            
            [self.chartParamsModel.formFields enumerateObjectsUsingBlock:^(DeviceChartFieldModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            
            [self.lcuFieldData enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            //将参数值合并到model中
            [self macthLocalJsonFile];
            [self.tableView reloadData];
        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
    }];
}


#pragma mark ------1. 233 EMU参数信息中包含了除湿机的数据点 ---------
-(void)getDehumInfo
{
    [QMUITips showLoadingInView:self.view];
       NSDictionary *para = @{@"deviceId":ValidNullData(self.curDevModel.deviceId),
                              @"endpointTypeCode":@[@"DHM"],
                              @"group":@(1)};
    [RHEndPointModel startWithCompletionAPIKey:H_getEndpointByType argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
        
            if([request.responseJSONObject[@"data"] isKindOfClass:[NSArray class]]){
                NSArray *dataArr = request.responseJSONObject[@"data"];
                NSDictionary *dataDic = [dataArr firstObject];
                if([dataDic[@"endpointList"] isKindOfClass:[NSArray class]]){
                    NSArray *endPointArr = [NSArray yy_modelArrayWithClass:[RHEndPointModel class] json:dataDic[@"endpointList"]];
                    RHEndPointModel *dehumModel = [endPointArr firstObject];
                    if (dehumModel) {
                        self.dehumEndpointModel = dehumModel;
                        [self getDehumParamList:dehumModel.endpointTypeId];
                    }
                    
                }
            }

        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
        
    }];
}

#pragma mark ----2. 获取 除湿机 模块参数
- (void)getDehumParamList:(NSInteger)enpointTypeId
{
    NSDictionary *para = @{
        @"endpointTypeId": @(enpointTypeId),
        @"styles": @[@(1), @(2)],
        @"deviceTypeCode":self.curDevModel.deviceTypeCode
       };
    [DeviceChartFieldModel startWithCompletionAPIKey:H_getDataByStyle argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        self.dehumFieldData = resultModel.data;
        //匹配文件里的key
        [self macthLocalJsonFile];
        //读取参数值
        [self getDehumFormFieldData];
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}

#pragma mark -------3. 获取EMU参数信息中的 除湿机 数据点 ----------
-(void)getDehumFormFieldData
{
    if (!self.dehumEndpointModel) {
        return;
    }
    //电表参数
    NSMutableArray *paraKey = [NSMutableArray array];
    [self.dataArray enumerateObjectsUsingBlock:^(RHInverterModel*  _Nonnull invSectionModel, NSUInteger idx, BOOL * _Nonnull stop) {
        [invSectionModel.rowDataArr enumerateObjectsUsingBlock:^(RHInverterModel * _Nonnull rowModel, NSUInteger idx, BOOL * _Nonnull stop) {
            //有一维数组和二维数组两种情况
            [rowModel.rowKeys enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                //一维数组
                if ([obj isKindOfClass:[NSString class]]) {
                    if ([obj hasPrefix:@"dehum_"]) {
                        [paraKey addObject:obj];
                    }
                }
            }];
            
           
        }];
        
        [invSectionModel.rowKeys enumerateObjectsUsingBlock:^(NSString*  _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([key hasPrefix:@"dehum_"]) {
                [paraKey addObject:key];
            }
            
        }];

    }];
    
    if (paraKey.count==0) return;
    
    NSDictionary *para = @{@"deviceId":self.curDevModel.deviceId,
                           @"endpointTypeCode":SafeStr(self.dehumEndpointModel.endpointCode),
                           @"keyCodes":paraKey,
                           @"endpointSn":SafeStr(self.dehumEndpointModel.sn)
    };
    [BaseModel startWithCompletionAPIKey:D_getLastEndpointData argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
        if(resultModel.code == 200){
            
            NSDictionary *dic;
            if ([request.responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
                dic = request.responseObject[@"data"];
            }
            
            [self.chartParamsModel.formFields enumerateObjectsUsingBlock:^(DeviceChartFieldModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            
            [self.dehumFieldData enumerateObjectsUsingBlock:^(DeviceChartFieldModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (dic[obj.keyCode]) {
                    obj.content = dic[obj.keyCode];
                }
            }];
            //将参数值合并到model中
            [self macthLocalJsonFile];
            [self.tableView reloadData];
        }
        
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
    }];
}


#pragma mark ------- 获取电表某一天的最后一条数据
-(void)getMeterFormDataWithDate
{
    kWeakSelf;
    WSDatePickerView *datePickerV = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDay CompleteBlock:^(NSDate *selectDate) {
        self.meterDate = selectDate;
        [weakSelf getFormData];
    }];
    datePickerV.dateLabelColor = FontColor(@"#3ECE80");//年-月 颜色
    datePickerV.datePickerColor = UIColorBlack;//滚轮日期颜色
    datePickerV.doneButtonColor = UIColor.blackColor;//确定按钮的颜色
   
    datePickerV.maxLimitDate = [NSDate date];
    datePickerV.minLimitDate = [NSDate dateWithYear:[NSDate date].year-5 month:[NSDate date].month day:[NSDate date].day hour:[NSDate date].hour minute:[NSDate date].minute second:[NSDate date].second];
    
    [datePickerV show];

}
#pragma mark -------1. 电芯电压和温度数据
-(void)createCellData
{
    if (self.cellDataArray) {
        return;
    }
    NSArray *sectionTitles = @[@"电压统计".rh_localized,@"温度统计".rh_localized];
    NSArray *subTitleArr = @[@"单体电池电压实时曲线".rh_localized,@"单体电池温度实时曲线".rh_localized];
    NSArray *unitArr = @[[NSString stringWithFormat:@"%@(V)",@"电压".rh_localized],[NSString stringWithFormat:@"%@(℃)",@"温度".rh_localized]];
    NSMutableArray *tempArr = [NSMutableArray array];
    [sectionTitles enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        RHCellRealDataModel *model = [[RHCellRealDataModel alloc]init];
        model.sectionTitle = sectionTitles[idx];
        model.title = subTitleArr[idx];
        model.unit = unitArr[idx];
        [tempArr addObject:model];
    }];
    self.cellDataArray = tempArr.copy;
}

#pragma mark -----2. 根据master获取 pack和电芯数据 233kWh
-(void)getPackInfoWithMaster:(NSString*)masterSN
{
    [QMUITips showLoadingInView:self.view];
    NSDictionary *para = @{@"deviceId":ValidNullData(self.curDevModel.deviceId),
                           @"masterSn":ValidNullData(masterSN)};
    [RHDevPackModel startGetWithCompletionAPIKey:H_getPackCellData argument:para requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
          
            NSArray *arr = resultModel.data;
            //电压数据
            NSMutableArray *vArray = [NSMutableArray array];
            //温度数据
            NSMutableArray *tArray = [NSMutableArray array];
            
            
            [arr enumerateObjectsUsingBlock:^(RHDevPackModel  *_Nonnull packModel, NSUInteger idx, BOOL * _Nonnull stop) {
                [packModel.volt enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    [vArray addObject:ValidNullDataToString(obj, @"0")];
                    //233的电芯温度是按照  2 3 3 的序号读取
                    NSInteger shareCount = (idx+1)*19/51;//233的电芯温度是 以233的序号分布
//                    NSLog(@"---->索引%ld取值下标:%ld",idx,shareCount);
                    [tArray addObject:ValidNullDataToString([packModel.temp safeObjectAtIndex:shareCount], @"0")];
                    
                }];
  
            }];
            
            NSMutableArray *xValues = [NSMutableArray array];
            for (int i = 0; i < vArray.count; i++) {
                [xValues addObject:[NSString stringWithFormat:@"%d",i]];
            }
            
            
            RHCellRealDataModel *voltModel = [self.cellDataArray firstObject];
            voltModel.title = @"单体电压实时曲线".rh_localized;
            voltModel.packArr = arr;
            voltModel.yValues = vArray;
            voltModel.color = @"8956F8";
            voltModel.xValues = xValues.copy;
            
            RHCellRealDataModel *tempModel = [self.cellDataArray lastObject];
            tempModel.title = @"单体温度实时曲线".rh_localized;
            tempModel.packArr = arr;
            tempModel.yValues = tArray;
            tempModel.color = @"FDD015";
            tempModel.xValues = xValues.copy;
            
            if (vArray.count == 0) {
                voltModel.yValues = @[@(0)];
                voltModel.xValues = @[@""];
                voltModel.maxValue = 100;
                
                tempModel.yValues = @[@(0)];
                tempModel.xValues = @[@""];
                tempModel.maxValue = 100;
            }
           
        }
        [self.tableView reloadData];
        [self.tableView endHeaderRefresh];
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        [self.tableView endHeaderRefresh];
    }];
        
}

//电芯电压全屏
-(void)fullCellVolChartAction:(RHCellRealDataModel*)cellDataModel
{
    RHBatteryClusterFullChartVC *fullVC = [[RHBatteryClusterFullChartVC alloc]initWithModel:cellDataModel];
    [self.navigationController pushViewController:fullVC animated:NO];
}

- (void)setupUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setBackgroundColor:UIColor.clearColor];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    [_tableView setEstimatedSectionFooterHeight:0];
    [_tableView setSectionFooterHeight:0];
    [_tableView registerClass:[RHDeviceTotalDataCell class] forCellReuseIdentifier:@"RHDeviceTotalDataCell"];
    [_tableView registerClass:[RHDeviceItemDataCell class] forCellReuseIdentifier:@"RHDeviceItemDataCell"];
    [_tableView registerClass:[RHInverterStatisticsCell2 class] forCellReuseIdentifier:@"RHInverterStatisticsCell2"];
    [_tableView registerClass:[RHInverterStatisticsCell3 class] forCellReuseIdentifier:@"RHInverterStatisticsCell3"];
    [_tableView registerClass:[RHInverterParamterCell class] forCellReuseIdentifier:@"RHInverterParamterCell"];
    [_tableView registerClass:[RHInvDoubleChartCell class] forCellReuseIdentifier:@"RHInvDoubleChartCell"];
    [_tableView registerClass:[RHParaSingleCell class] forCellReuseIdentifier:@"RHParaSingleCell"];
    [_tableView registerClass:[KWTParaItemCell class] forCellReuseIdentifier:@"KWTParaItemCell"];
    [_tableView registerClass:[KWTParaItemCell class] forCellReuseIdentifier:@"KWTParaItemCell_LCU"];
    [_tableView registerClass:[KWTParaItemCell class] forCellReuseIdentifier:@"KWTParaItemCell_DHM"];
    [_tableView registerClass:[KWTParaMeterCell class] forCellReuseIdentifier:@"KWTParaMeterCell"];
    [_tableView registerClass:[RHBatteryClusterChartCell class] forCellReuseIdentifier:@"RHBatteryClusterChartCell"];
    _tableView.estimatedRowHeight = 380;
    if (self.endPointTypeModel.nodes.count>0) {
        _tableView.tableHeaderView = self.headerView;
    }
    
    [self.view addSubview:_tableView];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    kWeakSelf;
    [_tableView addHeaderRefresh:^{
        [weakSelf getDeviceData];
        [weakSelf getSubEndpointListInfo];
        //233k master端点下面的电芯电压和温度
        BOOL is233 = [weakSelf.curDevModel.deviceTypeCode is233DeviceType];
        if ([weakSelf.endPointTypeModel.endpointTypeCode isEqualToString:@"Master"]&& is233) {
            [weakSelf getPackInfoWithMaster:weakSelf.curEndPointModel.sn];
        }
        if (weakSelf.pcsEndpointModel) {
            [weakSelf getPcsFormFieldData];
        }
        if (weakSelf.meterEndpointModel) {
            [weakSelf getMeterFormFieldData];
        }
        if (weakSelf.masterEndpointModel) {
            [weakSelf getMasterFormFieldData];
        }
        if (weakSelf.updateDevStatus) {
            weakSelf.updateDevStatus();
        }
        //1.部件列表进来获取设备在状态  2.设备详情里设备拓扑图进来获取备电时长
        if (weakSelf.isFromEndpoint||[weakSelf.endPointTypeModel.endpointTypeCode isEqualToString:@"Pack"]) {
            [weakSelf getDeviceInfo];
        }
    }];
    
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = 0;
    }

    _tableView.ly_emptyView = [LYEmptyView emptyViewWithImageStr:@"nodata_icon_1" titleStr:@"没有数据".rh_localized detailStr:@""];
}

- (UIView *)headerView{
    if(!_headerView){
        
        _headerView = [[RHInvChartHeaderView alloc]initWithEndPointTypeModel:self.endPointTypeModel deviceModel:self.curDevModel];
        if(self.endPointTypeModel.nodes.count>0){
            _headerView.endPointModel = [self.endPointTypeModel.nodes firstObject];
        }
        kWeakSelf;
        _headerView.selectBlock = ^{
            [UIView animateWithDuration:0.2 animations:^{
                weakSelf.headerView.arrowImg.transform = CGAffineTransformMakeRotation(M_PI/2);
            }];
            
            weakSelf.choiceEndpointVC = [[ChoiceEndpointVC alloc]init];
            weakSelf.choiceEndpointVC.endpointName = weakSelf.endPointTypeModel.endpointTypeName;
            weakSelf.choiceEndpointVC.dataList = weakSelf.endPointTypeModel.nodes;
            weakSelf.choiceEndpointVC.curModel = weakSelf.curEndPointModel;
            [[RHWindowTipManage shareWindowTipManage] showWithController:weakSelf.choiceEndpointVC];
            [weakSelf.choiceEndpointVC showAnimation];
            weakSelf.choiceEndpointVC.choiceResultBlock = ^(RHEndPointModel * _Nonnull model) {
                if (model) {
                    weakSelf.curEndPointModel = model;
                    weakSelf.headerView.endPointModel = model;
                    //重新获取子端点下的参数列表
                    [weakSelf getParamList:weakSelf.endPointTypeModel.endpointTypeId];
                }
                [UIView animateWithDuration:0.2 animations:^{
                    weakSelf.headerView.arrowImg.transform = CGAffineTransformIdentity;
                }];
            };
           
        };
        _headerView.batteryCellBlock = ^{
            RHDeviceBatteryVC *batteryVC = [[RHDeviceBatteryVC alloc]init];
            batteryVC.devModel = weakSelf.curDevModel;
            [weakSelf.navigationController pushViewController:batteryVC animated:YES];
        };
    }
    return _headerView;
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (self.endPointTypeModel.nodes.count == 0) {
        return 0;
    }
   return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
    
    RHInverterModel *sectionModel = self.dataArray[section];
    if ([sectionModel.sectionType isEqualToString:@"Electricity Statistics"]) {
        return sectionModel.rowDataArr.count;
    }
    //曲线
    if ([sectionModel.sectionType isEqualToString:@"Chart Line"]) {
        NSLog(@"---->返回%ld个图表",self.chartParamsModel.chartList.count);
        return self.chartParamsModel.chartList.count;
    }
    //数据点
    if ([sectionModel.sectionType isEqualToString:@"Run State"]) {
        return sectionModel.itemArr?1:0;
    }
    
    if ([sectionModel.sectionType isEqualToString:@"Meter Cell"]) {
        NSArray *arr = sectionModel.itemArr;
        return arr.count;
    }
    
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RHInverterModel *sectionModel = self.dataArray[indexPath.section];
    //数据点
    if ([sectionModel.sectionType isEqualToString:@"Run State"]) {
        if(sectionModel.itemArr.count == 0){
            return 0;
        }
    }

    return UITableViewAutomaticDimension;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    RHInverterModel *model = self.dataArray[section];
    if ([model.sectionType isEqualToString:@"Meter Cell"]) {
        return 70;
    }
    if (model.title.length>0) {
        return 60;
    }
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //没有组标题
    RHInverterModel *model = self.dataArray[section];
    if (model.title.length == 0) {
        return nil;
    }
    if ([model.sectionType isEqualToString:@"Parameter"]) {
        return nil;
    }
    //电表
    if ([model.sectionType isEqualToString:@"Meter Cell"]) {
        UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, 70)];
        headerView.backgroundColor = CFTabViewBgColor;
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(15, 10, kUI_WINDOW_W-30, 60)];
        [bgView setTopBorder];
        bgView.backgroundColor = UIColor.whiteColor;
        [headerView addSubview:bgView];
        QMUILabel *titleLab = [QMUILabel labelWithText:model.title.rh_localized font:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#171A1D")];
        titleLab.adjustsFontSizeToFitWidth = YES;
        titleLab.minimumScaleFactor = 0.8;
        titleLab.textAlignment = NSTextAlignmentLeft;
        [bgView addSubview:titleLab];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_offset(10);
        }];
        
        QMUILabel *timeTitleLab = [QMUILabel labelWithText:[NSString stringWithFormat:@"%@:",@"采样时间".rh_localized] font:kSYSTEMFONT(12) textColor:kCOLOR_HEX(@"#171A1D")];
        [bgView addSubview:timeTitleLab];
        [timeTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titleLab);
            make.top.equalTo(titleLab.mas_bottom).offset(5);
        }];
        
        QMUILabel *timeContentLab = [QMUILabel labelWithText:@"--" font:kSYSTEMFONT(12) textColor:kCOLOR_HEX(@"#171A1D")];
        [bgView addSubview:timeContentLab];
        [timeContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(timeTitleLab.mas_right);
            make.top.equalTo(timeTitleLab).offset(0);
        }];
        timeContentLab.text = [self.meterDate stringWithFormat:@"yyyy-MM-dd"];
        
        QMUIButton *timeBtn = [[QMUIButton alloc]init];
        [timeBtn setImage:[UIImage imageNamed:@"device_meter_time"] forState:UIControlStateNormal];
        [bgView addSubview:timeBtn];
        [timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(40);
            make.right.mas_offset(-10);
            make.centerY.mas_offset(0);
            make.left.equalTo(titleLab.mas_right).offset(0);
        }];
        
        UIView *line = kView;
        line.backgroundColor = kCOLOR_HEX_A(@"#7E868E", 0.2);
        [bgView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_offset(0);
            make.height.offset(1);
        }];
        kWeakSelf;
        [[timeBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
            [weakSelf getMeterFormDataWithDate];
        }];
        return headerView;
    }
    
    RHDeviceDataSectionView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
    header.backgroundColor = UIColor.blueColor;
    if(header == nil){
        header = [[RHDeviceDataSectionView alloc]initWithReuseIdentifier:@"header"];
    }
    kWeakSelf;
    [header.bgView setTopBorder];
    [header hideLine:YES];
    [header hideArrowView:YES];
    RHInverterModel *invertModel = self.dataArray[section];
    header.titleLab.text = invertModel.title.rh_localized;
    if([invertModel.sectionType isEqualToString:@"Run State"]&&invertModel.itemArr.count>6){
        [header hideArrowView:NO];
        header.seeMoreBlock = ^{
            [weakSelf seeFieldData:invertModel];
        };
    }
    if([invertModel.sectionType isEqualToString:@"Row Cell"] && invertModel.itemArr.count>3){
        [header hideArrowView:NO];
        header.seeMoreBlock = ^{
            [weakSelf seeOtherData:invertModel];
        };
    }
    
//    if ([invertModel.sectionType isEqualToString:@"Parameter"]) {
//        header.bgView.backgroundColor = CFTabViewBgColor;
//        [header hideLine:YES];
//    }else{
//        header.bgView.backgroundColor = UIColor.whiteColor;
//        [header hideLine:NO];
//    }
    
    return header;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    RHInverterModel *invertModel = self.dataArray[section];
    if([invertModel.sectionType isEqualToString:@"Run State"]){
        if (invertModel.itemArr.count == 0) {
            return 120;
        }
    }
   
    if([invertModel.sectionType isEqualToString:@"Chart Line"]){
        if (self.chartParamsModel.chartList.count == 0) {
            return 120;
        }
        return 15;
    }
    
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NSLog(@"---->返回组尾:%ld",section);
    RHInverterModel *invertModel = self.dataArray[section];
    if([invertModel.sectionType isEqualToString:@"Run State"]){
        //无数据点
        if (invertModel.itemArr.count == 0) {
            //
            UIView *nodataView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, 120)];
            LYEmptyView *emptyView = [LYEmptyView emptyViewWithImageStr:@"nodata_icon_1" titleStr:@"没有数据".rh_localized detailStr:@""];
            [nodataView addSubview:emptyView];
            return nodataView;
        }
        
        UITableViewHeaderFooterView *footer = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"footer_0"];
        if(footer == nil){
            footer = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"footer_0"];
            footer.backgroundColor = CFTabViewBgColor;
        }
        return footer;
    }else if([invertModel.sectionType isEqualToString:@"Chart Line"]){
        //无曲线数据
        if (self.chartParamsModel.chartList.count == 0) {
            UIView *nodataView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, 120)];
            LYEmptyView *emptyView = [LYEmptyView emptyViewWithImageStr:@"nodata_icon_1" titleStr:@"没有数据".rh_localized detailStr:@""];
            [nodataView addSubview:emptyView];
            return nodataView;
        }
        
        UITableViewHeaderFooterView *footer = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"footer_1"];
        if(footer == nil){
            footer = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"footer_1"];
            footer.frame = CGRectMake(0, 0, kUI_WINDOW_W, 10);
            UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, 10)];
            footView.backgroundColor = [UIColor clearColor];
            UIView *bgView = [[UIView alloc]init];
            [footView addSubview:bgView];
            bgView.backgroundColor = [UIColor whiteColor];
            bgView.frame = CGRectMake(15, 0, kUI_WINDOW_W-30, 10);
            [bgView setBottomBorder];
            [footer addSubview:footView];
        }
       
        return footer;
    }
    return nil;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSLog(@"----->返回:%ld组 %ld行",indexPath.section,indexPath.row);
    RHInverterModel *invertModel = self.dataArray[indexPath.section];
    //第一组光伏日发电量等信息
    if([invertModel.sectionType isEqualToString:@"Electricity Statistics"]){
        RHInverterModel *rowModel = invertModel.rowDataArr[indexPath.row];
        if (rowModel.rowKeys.count <3) {
            RHInverterStatisticsCell2 *cell2 = [tableView dequeueReusableCellWithIdentifier:@"RHInverterStatisticsCell2"];
            cell2.model = rowModel;
            return cell2;
        }else{
            RHInverterStatisticsCell3 *cell3 = [tableView dequeueReusableCellWithIdentifier:@"RHInverterStatisticsCell3"];
            cell3.model = rowModel;
            return cell3;
        }
        
    }
    
    //运行状态
    if([invertModel.sectionType isEqualToString:@"Run State"]){
        RHDeviceItemDataCell *itemCell = [tableView dequeueReusableCellWithIdentifier:@"RHDeviceItemDataCell"];
        
        [itemCell setFormFields:invertModel.itemArr deviceTypeCode:self.curDevModel.deviceTypeCode];
        
        [itemCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return itemCell;
    }else if([invertModel.sectionType isEqualToString:@"Chart Line"]){
        kWeakSelf;
        
        //如果超过三个单位的,也就是分成了两组的图表
        if (self.unitCount >2) {
            RHInvDoubleChartCell *twoChartCell = [tableView dequeueReusableCellWithIdentifier:@"RHInvDoubleChartCell"];
            [twoChartCell setSelectionStyle:UITableViewCellSelectionStyleNone];
            //把所有曲线都整过来
            NSMutableArray *mtbArr = [NSMutableArray array];
            [self.chartParamsModel.chartList enumerateObjectsUsingBlock:^(DevChartModel*  _Nonnull chartModel, NSUInteger idx, BOOL * _Nonnull stop) {
                [mtbArr addObjectsFromArray:chartModel.selectArray];
            }];
            DevChartModel *chartModel = self.chartParamsModel.chartList.firstObject;
            
            chartModel.selectArray = mtbArr;
            //            twoChartCell.chartModel = self.chartParamsModel.chartList.firstObject;
            twoChartCell.chartModel = chartModel;
            //选择参数
            twoChartCell.selectTopToolBlock = ^(NSInteger index) {
                [weakSelf selectTopTool:index atIndexpath:indexPath];
            };
            
            twoChartCell.subTimeBlock = ^{//日期往前
                [weakSelf subTimeAction:indexPath];
            };
            
            twoChartCell.addTimeBlock = ^{//日期往后
                [weakSelf addTimeAction:indexPath];
            };
            
            twoChartCell.changeTimeBlock = ^{//选择日期
                [weakSelf changeDate:indexPath];
            };
            
            return twoChartCell;
        }
        
        
        //两个单位以下的曲线
        RHDeviceChartDataCell *cell;
        DevChartModel *chartModel = self.chartParamsModel.chartList[indexPath.row];
        
        NSString *type = @"Day";
        //        if (chartModel.monthParams.count>0) {
        //            type = @"Month";
        //        }
        //        if (chartModel.yearParams.count>0) {
        //            type = @"Year";
        //        }
        NSString *reuseIdentifier = [NSString stringWithFormat:@"DeviceCell_%ld_%ld_%@",(long)indexPath.section,(long)indexPath.row,type];
        NSLog(@"----->identify:%@",reuseIdentifier);
        cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
        if (cell == nil) {
            cell = [[RHDeviceChartDataCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        }
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        [cell setChartModel:chartModel];
        
        //全屏
        cell.fullChartBlock = ^{
            [weakSelf fullAction:indexPath.row];
        };
        //选择参数
        cell.selectTopToolBlock = ^(NSInteger index) {
            [weakSelf selectTopTool:index atIndexpath:indexPath];
        };
        
        cell.subTimeBlock = ^{//日期往前
            [weakSelf subTimeAction:indexPath];
        };
        
        cell.addTimeBlock = ^{//日期往后
            [weakSelf addTimeAction:indexPath];
        };
        
        cell.changeTimeBlock = ^{//选择日期
            [weakSelf changeDate:indexPath];
        };
        
        BOOL hideSelectBtn = [self.curEndPointModel.endpointCode isEqualToString:@"LCU"]||[self.curEndPointModel.endpointCode isEqualToString:@"DHM"];
        [cell hideSelectBtn:hideSelectBtn];
        return cell;
    }else if ([invertModel.sectionType isEqualToString:@"Parameter"]) {
        //参数
        RHInverterParamterCell *paramCell = [tableView dequeueReusableCellWithIdentifier:@"RHInverterParamterCell"];
        paramCell.model = invertModel;
        kWeakSelf;
        paramCell.refreshBlock = ^{
            [weakSelf.tableView reloadData];
            
        };
        return paramCell;
    }else if ([invertModel.sectionType isEqualToString:@"Row Cell"]){//一行行的数据点
        RHParaSingleCell *singleCell = [tableView dequeueReusableCellWithIdentifier:@"RHParaSingleCell"];
        kWeakSelf;
        singleCell.contentSizeDidChangeBlock = ^{
            [weakSelf.tableView reloadData];
        };
        [singleCell setDataArr:invertModel.itemArr showCount:invertModel.showCount deviceTypeCode:self.curDevModel.deviceTypeCode];
        return singleCell;
    }else if ([invertModel.sectionType isEqualToString:@"Item Cell"]){
        if ([self.curEndPointModel.endpointCode isEqualToString:@"LCU"]) {
            KWTParaItemCell *itemCell = [tableView dequeueReusableCellWithIdentifier:@"KWTParaItemCell_LCU"];
            itemCell.sectionDataModel = invertModel;
            return itemCell;
        }
        if ([self.curEndPointModel.endpointCode isEqualToString:@"DHM"]) {
            KWTParaItemCell *itemCell = [tableView dequeueReusableCellWithIdentifier:@"KWTParaItemCell_DHM"];
            itemCell.sectionDataModel = invertModel;
            return itemCell;
        }
        KWTParaItemCell *itemCell = [tableView dequeueReusableCellWithIdentifier:@"KWTParaItemCell"];
        itemCell.sectionDataModel = invertModel;
        return itemCell;
    }else if ([invertModel.sectionType isEqualToString:@"Meter Cell"]){//电表
        KWTParaMeterCell *itemCell = [tableView dequeueReusableCellWithIdentifier:@"KWTParaMeterCell"];
        NSArray *arr = invertModel.itemArr;
        itemCell.model = [arr safeObjectAtIndex:indexPath.row];
        return itemCell;
    }else if ([invertModel.sectionType isEqualToString:@"Cell Voltage Line"]){
        RHBatteryClusterChartCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHBatteryClusterChartCell"];
        cell.chartModel = [self.cellDataArray firstObject];//电芯电压曲线
        kWeakSelf;
        cell.fullChartBlock = ^{
            [weakSelf fullCellVolChartAction:[self.cellDataArray firstObject]];
        };
        return cell;
    }else if ([invertModel.sectionType isEqualToString:@"Cell Temperature Line"]){
        RHBatteryClusterChartCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHBatteryClusterChartCell"];
        cell.chartModel = [self.cellDataArray lastObject];//电芯温度曲线
        kWeakSelf;
        cell.fullChartBlock = ^{
            [weakSelf fullCellVolChartAction:[self.cellDataArray lastObject]];
        };
        return cell;
    }
    
    
    return [UITableViewCell new];
}

-(RHInvParamSelectView *)paraSelectView
{
    if (!_paraSelectView) {
        _paraSelectView = [[RHInvParamSelectView alloc]initWithEndpointModel:self.curEndPointModel allFieldParams:self.allFieldData emuPrams:self.emuFieldData deviceTypeCode:self.curDevModel.deviceTypeCode];
        kWeakSelf;
        _paraSelectView.selectBlock = ^(NSArray * _Nonnull selectedModels) {
            
            [weakSelf combineData:selectedModels];
        };
    }
    return _paraSelectView;
}



#pragma mark - JXCategoryListContentViewDelegate
/**
 实现 <JXCategoryListContentViewDelegate> 协议方法，返回该视图控制器所拥有的「视图」
 */
- (UIView *)listView {
    return self.view;
}


@end
